package cn.zqy.demo.day05;

import java.util.Arrays;

public class Demo05ArrayFor {
    public static void main(String[] args) {
        // 数组遍历
        int[] arrA = {1,2,3,4,5,6,7,8,9,0};
        for (int i : arrA) {
            System.out.println(i);
        }

        System.out.println("========================");
        System.out.println("最大值： " + max(new int[] {1,23,3,3,3,6,0,-9,66}));
        System.out.println("最小值： " + min(new int[] {1,23,3,3,3,6,0,-9,66}));
        System.out.println("反转： " + Arrays.toString(rverse(new int[]{1, 23, 3, 3, 3, 6, 0, -9, 66})));
    }

    public static int max(int[] arr) {
        int max = arr[0];
        for (int i : arr) {
            max = i > max ? i : max;
        }
        return max;
    }

    public static int min(int[] arr) {
        int min = arr[0];
        for (int i : arr) {
            min = i < min ? i : min;
        }
        return min;
    }

    public static int[] rverse(int[] arr) {
        /*int[] arrCope = new int[arr.length];
        for (int i = 0 ,j = arr.length - 1; i < arr.length; i++, --j) {
            arrCope[j] = arr[i];
        }
        return arrCope;*/
        for (int i = 0, j = arr.length - 1; i <= j; i++, --j) {
            int preNum = arr[i];
            arr[i] = arr[j];
            arr[j] = preNum;
        }
        System.out.println("arr");
        return arr;
    }
}
